package com.bdqn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.entity.UmsPcdDic;
import com.bdqn.entity.responseDate.ums.PcdListDto;
import com.bdqn.mapper.UmsPcdDicMapper;
import com.bdqn.service.UmsPcdDicService;
import com.bdqn.util.Pet_service_RedisTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 省市区字典表 服务实现类
 * </p>
 *
 * @author hunter
 * @since 2022-04-30
 */
@Service
public class UmsPcdDicServiceImpl extends ServiceImpl<UmsPcdDicMapper, UmsPcdDic> implements UmsPcdDicService {
    @Autowired
    private UmsPcdDicMapper umsPcdDicMapper;
    @Autowired
    private Pet_service_RedisTemplate pet_service_redisTemplate;
    @Override
    public List<PcdListDto> pcdListDto() {
          //先从redis数据库进行查询 没有的话 再去mysql数据库查询
        List<PcdListDto> pcdListDto = pet_service_redisTemplate.getPcdListDto();
        System.out.println("====从redis中查询的省市县列表为===="+pcdListDto);
        if(pcdListDto!=null){
            //说明redis有
            return pcdListDto;
        }else {
            //不然就redis没有  去mysql查询
            //获取到省市县列表信息集合
            List<PcdListDto> pcdListDtoList = umsPcdDicMapper.pcdListDto();
            System.out.println("====从mysql中查询的省市县列表为===="+pcdListDtoList);
            //调用方法存到redis中
            int num = pet_service_redisTemplate.setPcdListDto(pcdListDtoList);
                //表示存入redis成功 否则表示存入redis失败
             return num>0?pcdListDtoList:null;
            }
    }
}
